<?php

namespace App\Entities\Auth;

use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use App\Libraries\Entities\BaseEntity;
use Illuminate\Auth\Authenticatable;
use Illuminate\Foundation\Auth\Access\Authorizable;

class Manager extends BaseEntity implements AuthenticatableContract, AuthorizableContract
{
    use Authenticatable, Authorizable;
    public $timestamps = true;
    protected $StatusFlag = true;
    protected $DescriptionFlag = true;
    protected $SortFlag = true;
    protected $table = 'auth_managers';
    public $primaryKey = 'manager_id';
    protected $fillable = [
        'name',
        'password',
        'username',
        'mobile',
        'email',
        'sex',
    ];

    protected $casts = [
        'status' => 'boolean',
        'sex' => 'boolean',
    ];

    protected $hidden = ['password'];

    /**
     * 密码加密设置.
     *
     * @param $value
     */
    protected function setPasswordAttribute($value)
    {
        $this->attributes['password'] = bcrypt($value);
    }

    /**
     * 拥有的角色.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
     */
    public function role()
    {
        return $this->morphedByMany(Role::class, 'categorytable', 'auth_user_relations', 'user_id');
    }
}
